﻿using System.Linq;
using System.Text;
using MRGSP.SurveyMaster.Core;
using MRGSP.SurveyMaster.Core.Model;
using MRGSP.SurveyMaster.Core.Service.Utils;

namespace MRGSP.SurveyMaster.Service.Utils
{
    public class GridRowCreateBuilder : IQuestionBuilder
    {
        public string Build(Question q)
        {
            var b = new StringBuilder();
           
            b.Append(
                string.Format(@"<td><div id='qwrap{0}'><div id='util{0}'>{2}{3}
                        </div>
                        {1}</div></td>", 
                                       q.Id, 
                                       HtmlGeneratorFactory.Generate(q),
                                       LinkBuilder.Build(LinkType.Edit, "editRow", q.Id),
                                       LinkBuilder.Build(LinkType.Remove, "deleteQuestion", q.Id)
                                       ));
            var ch = string.Empty;

            b.Append(q.Children.Aggregate(ch, (current, child) 
                => current + QuestionCreateBuilder.Get(ControlType.GridCell).Build(child)));
            
            return b.ToString();
        }
    }
}